package pers.lizs.test;

import org.springframework.beans.factory.xml.XmlBeanFactory;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Objects;

public class Main {

    //https://blog.csdn.net/tong472687551/article/details/109313762
    public static void main(String[] args) throws FileNotFoundException {
        String resource = Objects.requireNonNull(Main.class.getClassLoader().getResource("beans.xml")).getPath();
        XmlBeanFactory factory = new XmlBeanFactory(new FileInputStream(resource));
        // XmlBeanFactory继承了 AbstractBeanFactory，调用其getBean()方法
        // AbstractBeanFactory的singletonCache缓存单例对象，方便下次获取
        // DefaultListableBeanFactory的 beanDefinitionMap 存储beanDefinition对象
        ExampleBean bean1 = (ExampleBean) factory.getBean("bean1");//单例bean，bean.xml中singleton=true为默认
        System.out.println(bean1.getName());
        ExampleBean bean2 = (ExampleBean) factory.getBean("bean2");//多例bean，bean.xml中singleton=false
        System.out.println(bean2.getName());
    }
}
